/*
 * ThreadSafeList.h
 *
 *  Created on: Oct 26, 2014
 *      Author: toti
 */

#ifndef THREADSAFELIST_H_
#define THREADSAFELIST_H_




template <class T>
class ThreadSafeList{

private:


//	boost::mutex accessMutex;
//
//	boost::mutex conditionMutex;
//	boost::condition_variable conditionNotEmpty;

public:

	std::list<T> list;

	void push(T t);
	T pop();
	T popBlocking();

	void waitForData(int timeout);

	int getSize();
};

template <class T>
void ThreadSafeList<T>::push(T t){

//	accessMutex.lock();
	list.push_front(t);
//	accessMutex.unlock();

//	boost::mutex::scoped_lock lock(conditionMutex);
//	conditionNotEmpty.notify_all();

}

template <class T>
T ThreadSafeList<T>::pop(){

//	accessMutex.lock();
	T t = list.back();
	list.pop_back();
//	accessMutex.unlock();

	return t;
}

template <class T>
T ThreadSafeList<T>::popBlocking(){

//	boost::mutex::scoped_lock lock(conditionMutex);
//	while(getSize() == 0){
//		conditionNotEmpty.wait(lock);
//	}
//
//	accessMutex.lock();
	T t = list.back();
	list.pop_back();
//	accessMutex.unlock();

	return t;
}

template <class T>
void ThreadSafeList<T>::waitForData(int timeout){

//	boost::mutex::scoped_lock lock(conditionMutex);
//	while(getSize() == 0){
//		conditionNotEmpty.timed_wait(lock,timeout);
//	}
}

template <class T>
int ThreadSafeList<T>::getSize(){

	int size = 0;

//	accessMutex.lock();
	size = list.size();
//	accessMutex.unlock();

	return size;

}

#endif /* THREADSAFELIST_H_ */
